/**
 入驻小区
 **/
(function (vc) {
    var DEFAULT_PAGE = 1;
    var DEFAULT_ROWS = 10;
    vc.extends({
        data: {
            shopInfo: {
                openTypeName: ["", "商家", "服务", "商家和服务"],
                shops: [],
                total: 0,
                records: 1,
                moreCondition: false,
                shopId: '',
                codeUrl: '',
                shopTypes: [],
                conditions: {
                    ruleId: ''
                }
            }
        },
        _initMethod: function () {
            $that._listShops(DEFAULT_PAGE, DEFAULT_ROWS);
            $that._listShopTypes(1, 50);
        },
        _initEvent: function () {
            vc.on('shop', 'listShop', function (_param) {
                $that._listShops(DEFAULT_PAGE, DEFAULT_ROWS);
                $that._listShopTypes(1, 50);
            });
            vc.on('pagination', 'page_event', function (_currentPage) {
                $that._listShops(_currentPage, DEFAULT_ROWS);
            });
        },
        methods: {
            _listShopTypes: function (_page, _rows) {
                var param = {
                    params: {
                        page: _page,
                        row: _rows,
                    }
                };
                //发送get请求
                vc.http.apiGet('/shopType.queryShopType',
                    param,
                    function (json, res) {
                        let _json = JSON.parse(json);
                        $that.shopInfo.shopTypes = _json.data;
                    }, function (errInfo, error) {
                        console.log('请求失败处理');
                    }
                );
            },
            _listShops: function (_page, _rows) {
                $that.shopInfo.conditions.page = _page;
                $that.shopInfo.conditions.row = _rows;
                var param = {
                    params: $that.shopInfo.conditions
                };
                //发送get请求
                vc.http.apiGet('/shop.queryShop',
                    param,
                    function (json, res) {
                        var _shopInfo = JSON.parse(json);
                        $that.shopInfo.total = _shopInfo.total;
                        $that.shopInfo.records = _shopInfo.records;
                        $that.shopInfo.shops = _shopInfo.data;
                        vc.emit('pagination', 'init', {
                            total: $that.shopInfo.records,
                            dataCount: $that.shopInfo.total,
                            currentPage: _page
                        });
                    }, function (errInfo, error) {
                        console.log('请求失败处理');
                    }
                );
            },
            _openAddShopModal: function () {
                vc.emit('addShop', 'openAddShopModal', {});
            },
            _openEditShopModel: function (_shop) {
                vc.emit('editShop', 'openEditShopModal', _shop);
            },
            _openDeleteShopModel: function (_shop) {
                vc.emit('deleteShop', 'openDeleteShopModal', _shop);
            },
            _queryShopMethod: function () {
                $that._listShops(DEFAULT_PAGE, DEFAULT_ROWS);
            },
            _payFee: function (_shopId) {
                let _data = {
                    shopId: _shopId
                }
                vc.http.apiPost(
                    '/payment.toQrBondFeePay',
                    JSON.stringify(_data),
                    {
                        emulateJSON: true
                    },
                    function (json, res) {
                        let _json = JSON.parse(json);
                        if (_json.code != 0) {
                            vc.toast(_json.msg);
                            return;
                        }
                        let _data = _json.data;
                        vc.emit('viewQrCode', 'openQrCodeModal', {
                            title: '扫码缴保证金',
                            url: _data.qrCode,
                            remark: _data.remark,
                        });
                    },
                    function (errInfo, error) {
                        console.log('请求失败处理');
                        vc.toast(errInfo);
                    }
                );
            },
            _back: function () {
                $('#payFeeResult').modal('hide');
                $that._listShops(DEFAULT_PAGE, DEFAULT_ROWS);
            },
            
            _openShopQrCode: function (_shop) {
                vc.emit('viewQrCode', 'openQrCodeModal', {
                    title: _shop.shopName+"二维码",
                    url: _shop.phoneIndexUrl,
                    remark:  '手机扫码查看店铺',
                });
            },
            _moreCondition: function () {
                if ($that.shopInfo.moreCondition) {
                    $that.shopInfo.moreCondition = false;
                } else {
                    $that.shopInfo.moreCondition = true;
                }
            }
        }
    });
})(window.vc);
